package com.example.basic.web.controller.zoneDepot;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.zoneDepot.ZoneDepot;
import com.example.basic.web.request.ZoneDepotRequest;
import com.example.basic.web.service.zoneDepot.ZoneDepotService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@Api(value  = "库位管理", tags = {"库位管理"})
@RestController
@RequestMapping("/api/v1/byg/zoneDepot")
public class ZoneDepotController {

    @Resource
    private ZoneDepotService zoneDepotService;

    @Log(title = "库位管理", description = "保存库位信息")
    @ApiOperation(value = "保存库位信息", notes = "保存库位信息")
    @PostMapping("/saveDepot")
    public Result<Boolean> saveDepot(@ApiParam(name = "zoneDepotRequest", value = "模型", required = true) @RequestBody ZoneDepotRequest zoneDepotRequest) {
        return ResultGenerator.genSuccessResult(zoneDepotService.saveDepot(zoneDepotRequest));
    }

    @Log(title = "库位管理", description = "更新库位信息")
    @ApiOperation(value = "更新库位信息", notes = "更新库位信息")
    @PostMapping("/modify")
    public Result<ZoneDepot> modify(@ApiParam(name = "zoneDepot", value = "模型", required = true) @RequestBody ZoneDepot zoneDepot) {
        return ResultGenerator.genSuccessResult(zoneDepotService.modify(zoneDepot));
    }

    @Log(title = "库位管理", description = "详情")
    @ApiOperation(value = "详情", notes = "详情")
    @PostMapping("/detail")
    public Result<ZoneDepot> detail(@ApiParam(name = "depotCode", value = "库位编码") @RequestParam String depotCode) {
        return ResultGenerator.genSuccessResult(zoneDepotService.detail(depotCode));
    }

    @Log(title = "库位管理", description = "删除")
    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("/delete")
    public Result<Integer> delete(@ApiParam(name = "depotCode", value = "库位编码") @RequestParam String depotCode ) {
        return ResultGenerator.genSuccessResult(zoneDepotService.delete(depotCode));
    }

    @Log(title = "库位管理", description = "启用/禁用")
    @ApiOperation(value = "启用/禁用", notes = "启用/禁用")
    @PostMapping("/enableOrDisable")
    public Result<Integer> enableOrDisable(@ApiParam(name = "depotCode", value = "库位编码") @RequestParam String depotCode) {
        return ResultGenerator.genSuccessResult(zoneDepotService.enableOrDisable(depotCode));
    }

    @Log(title = "库位管理", description = "列表")
    @ApiOperation(value = "列表", notes = "列表")
    @PostMapping("/queryList")
    public Result<IPage<ZoneDepot>> queryList(
            @ApiParam(name = "pharmCode", value = "仓库编码") @RequestParam(required = false) String pharmCode,
            @ApiParam(name = "searchParam", value = "模糊搜索(编码)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "zoneCode", value = "分区编码") @RequestParam(required = false) String zoneCode,
            @ApiParam(name = "isAll", value = "是否查询全部 0-否，1-是") @RequestParam(defaultValue = "0") String isAll,
            @ApiParam(name = "page", value = "页数，list分页的第几页") @RequestParam(defaultValue = "0") Integer page,
            @ApiParam(name = "size", value = "条数，list分页的每页条数") @RequestParam(defaultValue = "0") Integer size) {
        Page<ZoneDepot> queryPage = new Page<>(page,size);
        return ResultGenerator.genSuccessResult(zoneDepotService.queryList(queryPage,searchParam, isAll,zoneCode,pharmCode));
    }

    @Log(title = "库位管理", description = "空闲库位")
    @ApiOperation(value = "空闲库位", notes = "空闲库位")
    @PostMapping("/freeDepotList")
    public Result<List<ZoneDepot>> freeDepotList(
            @ApiParam(name = "pharmCode", value = "仓库编码") @RequestParam(required = true) String pharmCode,
            @ApiParam(name = "zoneCode", value = "分区编码") @RequestParam(required = true) String zoneCode) {
        return ResultGenerator.genSuccessResult(zoneDepotService.freeDepotList(pharmCode,zoneCode));
    }
}
